#include "blockqueue.hpp"
#include"Task.hpp"
#include<unistd.h>



void* Product(void* args)
{
    BlockQueue<task_t>* bq =  static_cast<BlockQueue<task_t>*>(args);
    while(true)
    {
        std::cout << "正在写入任务" << std::endl;
        bq->EnterQueue(DownLoad);
        sleep(1);
    }

    return nullptr;
}

void* Comsume(void* args)
{
    BlockQueue<task_t>* bq =  static_cast<BlockQueue<task_t>*>(args);
    while(true)
    {
        task_t data =  bq->PopQueue();
        data();
    }

    return nullptr;
}

int main()
{
    BlockQueue<task_t>* bq = new BlockQueue<task_t>;
    pthread_t p[3];
    pthread_t c[2];
    pthread_create(p,nullptr,Product,bq);
    pthread_create(p+1,nullptr,Product,bq);
    pthread_create(p+2,nullptr,Product,bq);
    pthread_create(c,nullptr,Comsume,bq);
    pthread_create(c+1,nullptr,Comsume,bq);
    pthread_join(p[0],nullptr);
    pthread_join(p[1],nullptr);
    pthread_join(p[2],nullptr);
    pthread_join(c[0],nullptr);
    pthread_join(c[1],nullptr);
    delete bq;
    
    return 0;
}